package com.kgcx.common.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Created by zhulong on 17/11/20.
 */
public class DateTimeUtils {


    public static DateTimeFormatter dateTimeSecFormatter = DateTimeFormatter.ofPattern("YYYYMMddHHmmss");

    public static DateTimeFormatter dateTimeDayFormatter = DateTimeFormatter.ofPattern("YYYYMMdd");

    public static DateTimeFormatter dateTimeMonthFormatter = DateTimeFormatter.ofPattern("YYYYMM");


    /**
     * 日期转成数字类型 YYYYMMddhhmmss
     * @return
     */
    public static Long convertNumberSec  (LocalDateTime localDateTime) throws NumberFormatException {


        return Long.valueOf(localDateTime.format(dateTimeSecFormatter));

    }

    /**
     * 日期转成数字类型 YYYYMMdd
     * @return
     */
    public static Integer convertNumberDay  (LocalDateTime localDateTime) throws NumberFormatException {


        return Integer.valueOf(localDateTime.format(dateTimeDayFormatter));

    }
    /**
     * 日期转成数字类型 YYYYMM
     * @return
     */
    public static Integer convertNumberMonth  (LocalDateTime localDateTime) throws NumberFormatException {


        return Integer.valueOf(localDateTime.format(dateTimeMonthFormatter));

    }
}
